********************************************************************************
*** Voting for Populism in Europe Replication Files
*** Figure 4: Marginal Effect of Post-Crisis on Vote Shares
***
*** Required data files: "imputed_econdata_voteshare_merged.dta"
***                     
*** 
*** Created by: Thomas Cunningham
*** Date: 30 December 2020
******************************************************************


clear all
version 16.1
cd ..
 	
use "data/imputed/imputed_econdata_voteshare_merged.dta", clear

rename nuts2_main_left_vs mleft
rename nuts2_main_right_vs mright
rename nuts2_left_pop_vs lpop
rename nuts2_right_pop_vs rpop

la var shock_china_ind_L1 "China Shock 1 Lag"
la var shock_lowwage_ind_L1 "Low-Wage Imp Shock 1 Lag"
la var rti_region_L1 "RTI Region 1 Lag"
la var shock_fgn92_L1 "Migrant Shock 1 Lag"
la var shock_robots_mfg_L1 "Robot Shock 1 Lag"
la var shock_fdi_in_ind_L1 "FDI Shock 1 Lag"
la var postcrisis "Post-Crisis"	
la var reg_ict_emp_mfg_L1 "ICT 1 Lag"
la var inst_china_ind_L1 "US-China Instrument 1 Lag"
la var inst_lowwage_ind_L1 "US-Low-Wage Instrument 1 Lag"

* Figure 4: Marginal Effect of Post-Crisis on Vote Shares

mi est, post: reg mleft c.shock_china_ind_L1##i.postcrisis  shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1 reg_ict_emp_mfg_L1 shock_fgn92_L1  i.cwdyad, robust cluster(nuts_encoded)

sleep 10000

est store chntest_mleft_1
	
	
mimrgns, dydx(postcrisis) at(shock_china_ind_L1=(-1.5(.5)2.5)) predict(default)  vsquish  noestimcheck cmdmargins	

marginsplot, yline(0, lpattern(dash)) ///
	yscale(r(-60 40)) ///
	ylab(-60(20)40) ///
	recast(line) ///
    recastci(rarea) ///
    ciopts(fintensity(30) ///	
    lwidth(none)) ///
    xtitle("China Shock", size(medsmall)) ///
    ytitle("Marginal Effect of Post-Crisis", size(medsmall)) ///
	title("Center Left") ///
	scheme(s1mono) saving(mainleft_1, replace) 

mi est, post: reg mright c.shock_china_ind_L1##i.postcrisis  shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1 reg_ict_emp_mfg_L1 shock_fgn92_L1  i.cwdyad, robust cluster(nuts_encoded)

sleep 10000

est store chntest_mright_1
	
	
mimrgns, dydx(postcrisis) at(shock_china_ind_L1=(-1.5(.5)2.5)) predict(default)  vsquish  noestimcheck cmdmargins	


marginsplot, yline(0, lpattern(dash)) ///
	yscale(r(-60 40)) ///
	ylab(-60(20)40) ///
	recast(line) ///
    recastci(rarea) ///
    ciopts(fintensity(30) ///
    lwidth(none)) ///
    xtitle("China Shock", size(small)) ///
    ytitle("Marginal Effect of Post-Crisis", size(small)) ///
	title("Center Right") ///
	scheme(s1mono) saving(mainright_1, replace)
	

mi est, post: reg lpop c.shock_china_ind_L1##i.postcrisis  shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1 reg_ict_emp_mfg_L1 shock_fgn92_L1  i.cwdyad, robust cluster(nuts_encoded)

sleep 10000

est store chntest_lpop_1
	
	
mimrgns, dydx(postcrisis) at(shock_china_ind_L1=(-1.5(.5)2.5)) predict(default)  vsquish  noestimcheck cmdmargins	


marginsplot, yline(0, lpattern(dash)) ///
	yscale(r(-60 40)) ///
	ylab(-60(20)40) ///
	recast(line) ///
    recastci(rarea) ///
    ciopts(fintensity(30) ///
    lwidth(none)) ///
    xtitle("China Shock", size(small)) ///
    ytitle("Marginal Effect of Post-Crisis", size(small)) ///
	title("Left Populist") ///
	scheme(s1mono) saving(lpop_1, replace)	
	

mi est, post: reg rpop c.shock_china_ind_L1##i.postcrisis shock_fdi_in_ind_L1  shock_robots_mfg_L1 rti_region_L1 reg_ict_emp_mfg_L1 shock_fgn92_L1 i.cwdyad, robust cluster(nuts_encoded)

sleep 10000

est store chntest_rpop_1
	
mimrgns, dydx(postcrisis) at(shock_china_ind_L1=(-1.5(.5)2.5)) predict(default)  vsquish  noestimcheck cmdmargins	

marginsplot, yline(0, lpattern(dash)) ///
	yscale(r(-60 40)) ///
	ylab(-60(20)40) ///
	recast(line) ///
    recastci(rarea) ///
    ciopts(fintensity(30) ///
    lwidth(none)) ///
    xtitle("China Shock", size(small)) ///
    ytitle("Marginal Effect of Post-Crisis", size(small)) ///
	title("Right Populist") ///
	scheme(s1mono) saving(rpop_1, replace)	

gr combine rpop_1.gph lpop_1.gph mainleft_1.gph mainright_1.gph, ///
	title("Marginal Effect of Post-Crisis on Vote Shares") ///
	scheme(s1mono) ///
	note("Marginal Effects over 30 imputed datasets and 95% confidence intervals.", size(vsmall)) 
 
 
graph export "output/figure4.pdf", replace
erase "rpop_1.gph"
erase "lpop_1.gph"
erase "mainleft_1.gph" 
erase "mainright_1.gph"